package com.example.crm_system.controller;

import com.example.crm_system.config.Result;
import com.example.crm_system.entity.*;
import com.example.crm_system.service.WorkOrderService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/workOrder")
public class WorkOrderController {

    @Resource
    WorkOrderService workOrderService;

    // 插入work_order(cno,bno,status,note) ---工单创建
    @PostMapping("/insert")
    public Result insert(@RequestBody WorkOrder workOrder) {
        if (workOrder.getOno() == null) {
            workOrderService.insert(workOrder);
        } else {
            workOrderService.update(workOrder);
        }
        return Result.success();
    }

    // 修改work_order ---回单操作
    @PostMapping("/complete/{ono}")
    public Result complete(@PathVariable Integer ono) {
        workOrderService.complete(ono);
        return Result.success();
    }

    // 删除work_order ---退单操作
    @PostMapping("/cancel/{ono}")
    public Result cancel(@PathVariable Integer ono) {
        workOrderService.cancel(ono);
        return Result.success();
    }

    @DeleteMapping("/delete/{ono}")
    public Result delete(@PathVariable Integer ono) {
        workOrderService.delete(ono);
        return Result.success();
    }

    @GetMapping("/searchWorkOrder")
    public Result searchWorkOrder(Params params) {
        PageInfo<WorkOrder> list = workOrderService.searchWorkOrder(params);
        return Result.success(list);
    }
}
